package com.jprocms.module.cms.controller.admin.channel.vo;

import cn.hutool.core.collection.CollUtil;
import com.fasterxml.jackson.annotation.JsonIncludeProperties;
import com.jprocms.module.cms.dal.dataobject.model.ModelDO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.stream.Collectors;

@Schema(description = "前台栏目精简信息 Response VO")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ChannelFrontSimpleRespVO {

    @Schema(description = "ID")
    private Long id;

    @Schema(description = "名称")
    private String name;

    @Schema(description = "路径")
    private String path;

    @JsonIncludeProperties({"id", "name"})
    @Schema(description = "栏目模型")
    private ModelDO channelModel;

    @JsonIncludeProperties({"id", "name"})
    @Schema(description = "内容模型")
    private ModelDO contentModel;

    @Schema(description = "父 ID")
    private Long parentId;

    @Schema(description = "url")
    private String url;

    @Schema(description = "列表是否显示")
    private Boolean listStatus;

    @JsonIncludeProperties({"id", "name", "url", "path", "channelModel", "contentModel", "children", "listStatus"})
    private List<ChannelFrontSimpleRespVO> children;

    public List<ChannelFrontSimpleRespVO> getChildren() {
        if (CollUtil.isEmpty(children)) {
            return children;
        }
        return children.stream().filter(c -> Boolean.TRUE.equals(c.getListStatus())).collect(Collectors.toList());
    }

}
